package com.ruoyi.slope.ai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.ai.domain.SlopeAiModuleRegistry;
import com.ruoyi.slope.ai.service.ISlopeAiModuleRegistryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 三级模块目录Controller
 * 
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/ai/moduleRegistry")
public class SlopeAiModuleRegistryController extends BaseController
{
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeAiModuleRegistryService slopeAiModuleRegistryService;

    /**
     * 查询三级模块目录列表
     */
    @PreAuthorize("@ss.hasPermi('ai:moduleRegistry:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeAiModuleRegistry slopeAiModuleRegistry)
    {
        startPage();
        List<SlopeAiModuleRegistry> list = slopeAiModuleRegistryService.selectSlopeAiModuleRegistryList(slopeAiModuleRegistry);
        return getDataTable(list);
    }

    /**
     * 导出三级模块目录列表
     */
    @PreAuthorize("@ss.hasPermi('ai:moduleRegistry:export')")
    @Log(title = "三级模块目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeAiModuleRegistry slopeAiModuleRegistry)
    {
        List<SlopeAiModuleRegistry> list = slopeAiModuleRegistryService.selectSlopeAiModuleRegistryList(slopeAiModuleRegistry);
        ExcelUtil<SlopeAiModuleRegistry> util = new ExcelUtil<SlopeAiModuleRegistry>(SlopeAiModuleRegistry.class);
        String path = util.exportExcel(response, list, "三级模块目录数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取三级模块目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:moduleRegistry:query')")
    @GetMapping(value = "/{moduleId}")
    public AjaxResult getInfo(@PathVariable("moduleId") String moduleId)
    {
        return success(slopeAiModuleRegistryService.selectSlopeAiModuleRegistryByModuleId(moduleId));
    }

    /**
     * 新增三级模块目录
     */
    @PreAuthorize("@ss.hasPermi('ai:moduleRegistry:add')")
    @Log(title = "三级模块目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeAiModuleRegistry slopeAiModuleRegistry)
    {
        return toAjax(slopeAiModuleRegistryService.insertSlopeAiModuleRegistry(slopeAiModuleRegistry));
    }

    /**
     * 修改三级模块目录
     */
    @PreAuthorize("@ss.hasPermi('ai:moduleRegistry:edit')")
    @Log(title = "三级模块目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeAiModuleRegistry slopeAiModuleRegistry)
    {
        return toAjax(slopeAiModuleRegistryService.updateSlopeAiModuleRegistry(slopeAiModuleRegistry));
    }

    /**
     * 删除三级模块目录
     */
    @PreAuthorize("@ss.hasPermi('ai:moduleRegistry:remove')")
    @Log(title = "三级模块目录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moduleIds}")
    public AjaxResult remove(@PathVariable String[] moduleIds)
    {
        return toAjax(slopeAiModuleRegistryService.deleteSlopeAiModuleRegistryByModuleIds(moduleIds));
    }
}
